<?php

/**
 * Gets all companies
 * @package ModuleOrganisationCommunication
 * @version 1.0b
 * @return table
 */

session_start();

// Configuration file
include '../configuration.php';
// Functions
include '../inc/functions.php';

// Checking if user is logged in
if (!CheckSession()):
	exit();
endif;

// Include all objects
// TODO: Include only needed classes
foreach (glob($configuration['webroot'].'objects/*.php') as $class) { include_once $class; }

$company = new Company();
$companyList = $company->GetList(Array(Array('companyId', '>', '0')), 'name'); ?>

<table cellpadding="0" cellspacing="0" border="0" class="table-objects">
	<tr>
		<th class="check"></th>
		<th>#</th>
		<th>Nom</th>
		<th>Siège social</th>
	</tr>
	<?php foreach ($companyList as $company) {
		$activitysector = $company->GetActivitysector();
		$address = $company->GetAddressList(Array(Array('type', '=', 'MAINADDRESS')));
		$address = $address[0];
		
		$res  = '<tr>';
		$res .= '<td class="check"><input name="all" type="radio" value="'.$company->companyId.'"'.(($_POST['id'] == $company->companyId) ? ' checked="checked"' : '').' /></td>';
		$res .= '<td>'.$company->companyId.'</td>';
		$res .= '<td><span id="company-'.$company->companyId.'">'.$company->name.'</span></td>';
		$res .= '<td>'.$address->number.' '.$address->street.', '.$address->postalcode.' '.$address->city;
		$res .= '</tr>';
		echo $res;
	} ?>
</table>